<?php

namespace App\Admin\Metrics\Examples;

use Dcat\Admin\Widgets\Metrics\Line;
use Illuminate\Http\Request;

class userWalletRechargeLogLine extends Line
{

    /**
     * 初始化卡片内容
     *
     * @return void
     */
    protected function init()
    {
        parent::init();
        //$this->title = '充值订单统计';
        /*$this->dropdown([
            '7' => 'Last 7 Days',
            '15' => 'Last 28 Days',
            '30' => 'Last Month'
        ]);*/
        $this->subTitle('最近7天'); // 设置副标题
        $this->chartStraight(); // 设置直线

    }




    /**
     * 处理请求
     *
     * @param Request $request
     *
     * @return mixed|void
     */
    public function handle(Request $request)
    {

        // dd($result);
        // 卡片内容
        $this->withContent(0, 0);
        // 图表数据
        $this->withChart([0, 0, 0, 0, 0, 0, 0]);
        $date_list = [];
        // 7天日期
        for ($i = 7; $i >= 1; $i--) {
            $date_list[] = date("Y-m-d", strtotime("-{$i} day"));
        }
        $this->chartOption('dataLabels.enabled', true); // 显示金额
        $this->chartOption('tooltip.x.show', true); // 显示日期
        $this->chartOption('xaxis.categories', $date_list);

    }

    /**
     * 设置图表数据.
     *
     * @param array $money
     * @param array $number
     *
     * @return $this
     */
    public function withChart(array $money)
    {

        return $this->chart([
            'series' => [
                [
                    'name' => '金额',
                    'data' => $money,
                ]
            ]
        ]);
    }

    /**
     * 设置卡片内容.
     *
     * @param string $content
     *
     * @return $this
     */
    public function withContent($sum, $today_sum)
    {
        return $this->content(
            <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
    <h2 class="ml-1 font-lg-1">今日充值：￥ {$today_sum}</h2>
    <span class="mb-0 mr-1 text-80">最近7天充值：￥ {$sum}</span>
</div>
HTML
        );
    }
}
